import java.util.Date;

import rmi.Discussion;
import rmi.Me;
import rmi.Message;
import rmi.User;
import rmi.UserBuffer;
import rmi.UserInterface;
import controler.xmlReadWrite;

/**
 * @author arthur
 * 
 */
public class testXML {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(final String[] args) throws Exception {
		final Me me = new Me("Arthur", "kikolol", 1234);
		final UserBuffer friend1 = new UserBuffer(new User("Tim", "kikolol",
				1234, me), me);
		final UserBuffer friend2 = new UserBuffer(new User("Arnaud", "kikolol",
				1234, me), me);
		final UserBuffer friend3 = new UserBuffer("Sacha", "kikolol", 1234,
				new Date(), me);
		me.getFriends().put("Tim", friend1);
		me.getFriends().put("Arnaud", friend2);
		me.getFriends().put("Sacha", friend3);

		final Discussion d = new Discussion(me);
		d.getParticipants().add(friend1);
		d.getListMessages().add(
				new Message(friend1.getPseudo(), "jghfdjgkjd", "kikoo1"));
		d.getListMessages().add(
				new Message(me.getPseudo(), "jghfdjgkjd", "kikoo2"));

		final String dId = d.getId();

		final Discussion d2 = new Discussion(me);
		d2.getParticipants().add(friend2);
		d2.getListMessages().add(
				new Message(friend2.getPseudo(), "jghfdjgkjfdg", "kikoo12"));
		d2.getListMessages().add(
				new Message(me.getPseudo(), "jghfdjgkjgfd", "kikoo22"));

		System.out.println("saveMe");
		xmlReadWrite.saveMe(me, "/home/arthur/test.xml");

		System.out.println("restoreMe");
		final Me newMe = xmlReadWrite.restoreMe("/home/arthur/test.xml");

		System.out.println("saveDiscussions");
		xmlReadWrite.saveDiscussions(me.getCurrentDiscussions(),
				"/home/arthur/testXML");

		newMe.getCurrentDiscussions().add(
				xmlReadWrite
						.restoreOneDiscussion("/home/arthur/testXML/" + dId));

		System.out.println(newMe.getPseudo());
		for (final UserInterface u : newMe.getFriends().values()) {
			System.out.println(u.getPseudo());
		}

		for (final Discussion currentD : newMe.getCurrentDiscussions()) {
			System.out.println("Discussion :" + currentD.getId());
			for (final Message m : currentD.getListMessages()) {
				System.out.println(m.getAuthor() + "\n\t" + m.getMessage());
			}
		}
	}

}
